ALTER PROCEDURE [dbo].[spe_sms_datato44_A00012]
	-- Add the parameters for the stored procedure here
AS
BEGIN
	declare @count int
	declare @sms_guid varchar(36)
	
	select @COUNT=COUNT(*) from ucis_data_to_44 where TYPE_ID='A00012'
	if @COUNT>0
	begin
		--获取催缴计划
		select top 1 @sms_guid=sms_guid from ucis_data_to_44 where TYPE_ID='A00012'
		if @sms_guid!=''
		begin
			begin 
				--insert into OPENQUERY(UCIS115,'SELECT * from ucis.CJ_Comprehensive') select * from CJ_Comprehensive_UCIS where sms_guid=@sms_guid
				insert into OPENQUERY(UCIS115,'SELECT * from ucis.CJ_Comprehensive') select nf,yf,yhbh,tqje,yhbm,yhzh,lxdh,ysdz,sjhm,tqlx,tqrq1,tqrq2,tqsf,tqpsf,tqljf,id,tel_1,tel_2,tel1status,tel2status,smsstatus,DOC_GUID,CJ_GUID,type_id,ob_comment,sms_comment,t_result,t_result1,ob_comment1,ob_file,ob_file1,ob_result,ob_result1,KTY_SelSmsstatus,KTY_SelTelStatus,sms_sendtime,sms_guid,tel1_endtime,tel2_endtime,createdate,itemid,deptcode from (select *,row_number() over(partition  BY itemid ORDER BY itemid) as rk from Cj_Comprehensive_Ucis WHERE sms_guid = @sms_guid)t1 where rk=1;
			end
			begin
				insert into OPENQUERY(UCIS115,'SELECT * from ucis.CJ_UpdateType')(GUID,TypeID,DBType,InTime) values(@sms_guid,'A00012',1,GETDATE())
				delete ucis_data_to_44 where TYPE_ID='A00012' and sms_guid=@sms_guid
			end
		end
	end
end